<template>
  <div class="role">
    <el-card shadow="always">
      <div slot="header">
        <el-button
          type="primary"
          size="mini"
          @click="handleAdd"
        >新增角色</el-button>
      </div>
      <el-table :data="list" border stripe>
        <el-table-column type="index" label="#" />
        <el-table-column label="角色名称" prop="roleName" />
        <el-table-column label="角色编码" prop="roleCode" />
        <el-table-column label="备注" prop="remark" />
        <el-table-column label="添加时间" prop="createTime" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div>
              <el-button
                type="success"
                size="mini"
                @click="handleEdit(scope.row)"
              >编辑</el-button>
              <el-button
                size="mini"
                @click="handleDel(scope.row)"
              >删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer">
        <el-pagination
          :current-page.sync="page.start"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="page.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalNum"
          @size-change="sizeChange"
          @current-change="currentChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import { findRolesByPage } from '@/api/auth/role/index'
export default {
  data() {
    return {
      list: [],
      page: {
        start: 1,
        limit: 10,
        totalNum: 0
      }
    }
  },
  created() {
    this.getRoles()
  },
  methods: {
    // 获取角色列表
    async getRoles() {
      const { success, data, message } = await findRolesByPage(this.page.start, this.page.limit)
      if (success) {
        this.list = data.rows
        this.page.totalNum = data.total
      } else {
        this.$message.error(message)
      }
    },
    // 新增
    handleAdd() {},
    // 编辑
    handleEdit() {},
    // 删除
    handleDel() {}
  }
}
</script>
<style lang="scss" scope>
.role {
    margin: 30px;
    .footer {
        display: flex;
        justify-content: flex-end;
        margin-top: 30px;
    }
}
</style>
